import { http } from "@/utils/http";

type ResultTable = {
  total?: number;
  data?: Array<any>;
};

// 查询工单信息
export const queryOrderList = (data?: Record<string, any>) => {
  return http.request<ResultTable>("post", "/erc/api/v1/maintenanceWorkOrder/queryList", {
    data
  });
};

// 获取状态列表
export const getStatusList = (data?: Record<string, any>) => {
  return http.request("post", "/erc/api/v1/maintenanceWorkOrder/getWorkOrderStatusList", {
    data
  });
};

// 工单编码
export const getWorkOrderCode = () => {
  return http.request("post", `/erc/api/v1/maintenanceWorkOrder/getWorkOrderCode`);
};

// 获取故障类型树
export const getTypeTree = (data?: Record<string, any>) => {
  return http.request("post", "/erc/api/v1/eqpFaultType/queryTree", {
    data
  });
};

// 新增
export const addMaintainList = (data?: Record<string, any>) => {
  return http.request<Record<string, any>>("post", `/erc/api/v1/maintenanceWorkOrder/saveMaintenanceWorkOrder`, {
    data
  });
};

// 编辑
export const editMaintainList = (data?: Record<string, any>) => {
  return http.request<Record<string, any>>("post", `/erc/api/v1/maintenanceWorkOrder/updateMaintenanceWorkOrder`, {
    data
  });
};

// 撤回任务
export const backMaintainList = (data?: Record<string, any>) => {
  return http.request("post", `/erc/api/v1/maintenanceWorkOrder/cancelMaintenanceWorkOrder`, {
    data
  });
};

// 详情
export const detailMaintainList = (data?: Record<string, any>) => {
  return http.request<Record<string, any>>("post", `/erc/api/v1/maintenanceWorkOrder/getMaintenanceWorkOrder`, {
    data
  });
};

// 工单上传图片moduleName
export const getModuleName = () => {
  return http.request("post", `/erc/api/v1/maintenanceWorkOrder/getFileModelName`);
};

// 工单上传图片moduleName
export const getModuleRecordName = () => {
  return http.request("post", `/erc/api/v1/maintenanceWorkOrder/getFileModelName`);
};

// 维修记录列表
export const getRecordList = data => {
  return http.request("post", `/erc/api/v1/maintenanceRecord/queryList/${data}`);
};

// 新增维修记录
export const addRecord = data => {
  return http.request("post", `/erc/api/v1/maintenanceRecord/saveMaintenanceRecord`, {
    data
  });
};

// 编辑维修记录
export const editRecord = data => {
  return http.request("post", `/erc/api/v1/maintenanceRecord/updateMaintenanceRecord`, {
    data
  });
};

// 处理进度
export const queryDealProcess = (data?: object) => {
  return http.request<any[]>("post", "/erc/api/v1/approvalRecord/queryApprovalList", {
    data
  });
};

// 完成维修
export const finishMaintain = (data?: Record<string, any>) => {
  return http.request("post", `/erc/api/v1/maintenanceWorkOrder/submitMaintenanceWorkOrder`, {
    data
  });
};

// 审批
export const auditMaintainList = (data?: Record<string, any>) => {
  return http.request("post", `/erc/api/v1/approvalRecord/saveMaintenanceApproval`, {
    data
  });
};

// 转审
export const forwardMaintainList = (data?: Record<string, any>) => {
  return http.request("post", `/erc/api/v1/approvalRecord/saveMaintenanceTransfer`, {
    data
  });
};

// 根据关联单号查询工单id
export const getMaintainOrderNum = (data?: Record<string, any>) => {
  return http.request<string>("post", `/erc/api/v1/maintenanceWorkOrder/queryWorkIdByRelatedOrderNum`, {
    data
  });
};
export interface GetApprovalStatusListRes {
  /*枚举值 */
  value: string;

  /*枚举名称 */
  name: string;
}

/**
 * 审批状态
 * @returns
 */
export function getApprovalStatusList(): Promise<GetApprovalStatusListRes[]> {
  return http.post(`/erc/api/v1/approvalRecord/getApprovalStatusList`);
}
